import React, { useState, useEffect } from 'react';
import request from '@/utils/request';

function useOrderAttrList(attrNbr) {
  const [orderAttrList, setOrderAttrList] = useState([]);
  const [loading, setLoading] = useState(false);

  useEffect(() => {
    setLoading(true);
    request('/pmc/pms/StaticDataController/getAttrValueList.do', {
      data: {
        busiObjNbr: 'CustOrder',
        attrNbr,
      },
      timeout: 5000,
    })
      .then(res => {
        if (Array.isArray(res)) {
          setOrderAttrList(res);
        }
        setLoading(false);
      })
      .catch(() => {
        setLoading(false);
      });
  }, []);

  return [orderAttrList, loading];
}

export default useOrderAttrList;
